import fs from 'fs';

function getFile(fpath){
    return new Promise(function (resolve, reject) {
        fs.readFile(fpath,'utf8',(err,data)=>{
            if (err) {
                return reject(err);
            }
            resolve(data);
        })
    });
}


//调用该方法
getFile('./files/f1.txt').then((res)=>{
    console.log('success',res);
},(err)=>{
    console.log('err',err.message)
});


getFile('./files/f999.txt').then((res)=>{
    console.log('success',res);
}).catch((err)=>{
    console.log('err',err.message)
});